// file文件实现本地预览
export const getObjectURL = {
  // 方式1
  createObjectURL({ target }: any) {
    const { files } = target;
    const file = files[0];
    let url = null;
    const win: any = window
    if (win.createObjectURL != undefined) {
      url = win.createObjectURL(file);
    } else if (win.URL != undefined) {
      url = win.URL.createObjectURL(file);
    } else if (win.webkitURL != undefined) {
      url = win.webkitURL.createObjectURL(file);
    }
    target.value = null;
    return url;
  },
  // 方式2
  readAsDataURL({ target }: any, cb: (arg0: any) => any) {
    const { files } = target;
    const file = files[0];
    const reader = new FileReader();
    reader.onloadend = function (e: any) {
      target.value = null;
      cb && cb(e.target.result)
    }
    reader.readAsDataURL(file);
  }
}